<?php defined('BASEPATH') or exit('No direct script access allowed');
class Bet_type_m extends L_Model
{
	public function __construct(){	
		parent::__construct();
		$this->set_table_name("bet_type");
	}
	
	function get_all_with_cache() {
		if(isset($_SERVER['ALL_BET_TYPES'])) {
			return $_SERVER['ALL_BET_TYPES'];
		}
		
		$sql = "SELECT DISTINCT l_bet_type.* FROM l_bet_type ORDER BY odds"; 
		$bet_types = $this->db->query($sql)->result_object();
		$_SERVER['ALL_BET_TYPES'] = $bet_types;
		return $bet_types;
	}
	
	function get_by_id_with_cache($bet_type_id) {
		if(isset($_SERVER['BET_TYPES'])) {
			if (isset($_SERVER['BET_TYPES'][$bet_type_id])) {
				return $_SERVER['BET_TYPES'][$bet_type_id];
			}
		} else {
			$_SERVER['BET_TYPES'] = array();
		}
		$sql = "SELECT l_bet_type.* FROM l_bet_type WHERE id = ?"; 
		$bet_type = $this->db->query($sql, array($bet_type_id))->row();
		$_SERVER['BET_TYPES'][$bet_type_id] = $bet_type;
		return $bet_type;
	}
	
	function find_by_channel_type_with_cache($channel_type) {
		if(isset($_SERVER['BET_TYPES_'.$channel_type])) {
			return $_SERVER['BET_TYPES_'.$channel_type];
		}
		
		$sql = "SELECT DISTINCT l_bet_type.* FROM l_bet_type WHERE channel_type = ? ORDER BY sort_order"; 
		$bet_types = $this->db->query($sql, array($channel_type))->result_object();
		$_SERVER['BET_TYPES_'.$channel_type] = $bet_types;
		return $bet_types;
	}
}